import Vue from "vue";

// 处理大小写
function changeStr(str) {
    return str.charAt(0).toUpperCase() + str.slice(1)
}
let toCamelCase = function(value) {
	const underscoreRegex = /(?:[^\w\s]|_)+/g,
	    sandwichNumberRegex = /(\d)\s+(?=\d)/g,
	    camelCaseRegex = /(?:^\s*\w|\b\w|\W+)/g;
    if (/^\s*_[\s_]*$/g.test(value)) {
        return '_';
    }
    return value.replace(underscoreRegex, ' ')
        .replace(sandwichNumberRegex, '$1_')
        .replace(camelCaseRegex, function(match, index) {
            if (/^\W+$/.test(match)) {
                return '';
            }

            return index == 0 ? match.trimLeft().toLowerCase() : match.toUpperCase();
        });
}
// 批量匹配注册
const requireComponent = require.context('.', true, /\w+\.vue$/)
requireComponent.keys().forEach(fileName => {
    const config = requireComponent(fileName)
	const componentName = changeStr(
	   toCamelCase(fileName.split("/").pop().replace(/\.\w+$/, ''))
	)
    Vue.component(componentName, config.default || config)
})